#{extends 'main.html' /}
#{set title:'View module' /}

#{moduleEditBar 
    module:module, 
    moduleVersion:moduleVersion,
    user:user /}

#{if module.github}
    #{set 'moreScripts'}
    <script src="@{'/public/javascripts/github.js'}" type="text/javascript" charset="${_response_encoding}"></script>
    <script type="text/javascript">
        loadModuleInfoFromGitHub("${module.githubOwner}","${module.githubProject}");
    </script>
    #{/set}
#{/if}

#{if module.canEdit(user)}
    #{set 'help'}
    <p>
        If you want to change the module´s <b>friendly name</b>, its <b>home page</b>, <b>code</b> or
        <b>issue tracker</b> URLs, as
        well as <b>grant administration permissions</b> on this module for your colleagues,
        or even <b>transfer it</b> to an other user,
        go to the <a href="@{LoggedInRepo.editForm(module.name)}" class="btn btn-mini"
                     title="Edit this module"><i class="icon-edit"></i> edit</a> page.
    </p>
    <p>
        The <b>module name</b> and <b>version</b> are taken from the module descriptor.
    </p>
    <p>
        If your <b>code URL</b> points to a <a href="http://github.com">Github</a> project, we will extract
        its <b>icon</b>, <b>description</b> and <b>open issues</b> from it.
    </p>
    #{/set}
#{/if}

<table class="table table-bordered">
    <caption>Module info</caption>
    <tbody>
        <tr>
            <th>Name</th>
            <td>
                <div id="img-holder" class="pull-right"></div>
                #{user module.owner, img:true /} / <a href="@{Repo.versions(module.name)}" title="View published versions">${module.name}</a> / ${moduleVersion.version}
                #{if module.friendlyName}
                    <br/>${module.friendlyName}
                #{/if}
            </td>
        </tr>
        #{if module.category}
            <tr>
            	<th>Category</th>
            	<td>
            		<a href="@{Repo.category(module.category.name)}" title="Category module list"><i class="icon-book"></i> ${module.category.name}</a>
    				#{categoryDescription module.category /}     			
            	</td>
            </tr>
        #{/if}
        <tr>
            <th>Backends</th>
            <td>
                #{moduleBackends moduleVersion/}
            </td>
        </tr>
        #{if moduleVersion.isCarPresent || moduleVersion.isJarPresent}
        <tr>
            <th>Maven coordinates</th>
            <td>
                ${moduleVersion.mavenCoordinates}
            </td>
        </tr>
        #{/if}
        #{if moduleVersion.isCarPresent || moduleVersion.isJsPresent}
        <tr>
            <th>Compatible Ceylon release</th>
            <td>
                #{if moduleVersion.isCarPresent}
                    #{moduleCeylonCompatibility moduleVersion/}<br/>
                #{/if}
                #{if moduleVersion.isJsPresent}
                    #{moduleJsCompatibility moduleVersion/}
                #{/if}
            </td>
        </tr>
        #{/if}
        <tr>
            <th>Published</th>
            <td>${moduleVersion.published.sinceInUserTZ(true)}</td>
        </tr>
        <tr>
            <th>Stats</th>
            <td>
                #{if moduleVersion.isCarPresent || moduleVersion.isJarPresent}
                    <b>Downloads (JVM):</b> ${moduleVersion.downloads}<br/>
                #{/if}
                #{if moduleVersion.isJsPresent}
                    <b>Downloads (JS):</b> ${moduleVersion.jsdownloads}<br/>
                #{/if}
                <b>Source downloads:</b> ${moduleVersion.sourceDownloads}<br/>
            </td>
        </tr>
        #{if moduleVersion.authors}
            <tr>
                <th>Authors</th>
                <td>
                    #{list moduleVersion.authors}
                        ${_.name}<br/>
                    #{/list}
                </td>
            </tr>
        #{/if}
        #{if moduleVersion.license}
            <tr>
                <th>License</th>
                <td>${moduleVersion.license}</td>
            </tr>
        #{/if}
        #{if moduleVersion.doc || module.github}
            <tr>
                <th>Description</th>
                <td>
                    #{moduleDescription moduleVersion:moduleVersion/}
        
                    <div id="description"></div>
                </td>
            </tr>
        #{/if}
        #{if moduleVersion.changelog || module.canEdit(user)}
            <tr>
                <th>Change Log</th>
                <td>
                    #{if module.canEdit(user)}
                        <a href="@{LoggedInRepo.editChangelog(module.name, moduleVersion.version)}" 
                            class="btn btn-mini pull-right" title="Edit change log for this version">
                            <i class="icon-list"></i> Edit change log
                        </a>
                    #{/if}
                    #{if moduleVersion.changelog}
                        <div class="moduleChangelog" #{if moduleVersion.changelog.size() > 150}data-behaviour="expandable"#{/if}>
                            ${moduleVersion.changelog.md(moduleVersion)}
                        </div>
                    #{/if}
                </td>
            </tr>
        #{/if}
        #{if moduleVersion.dependencies}
            <tr>
                <th>Dependencies</th>
                <td>
                    #{if moduleVersion.jvmDependencies || moduleVersion.jsDependencies}
                    <table class="table">
                        <tr>
                            <th>All backends</th>
                            <th><span class="label label-jvm">JVM</span></th>
                            <th><span class="label label-js">JavaScript</span></th>
                        </tr>
                        <tr>
                            <td>
                                #{moduleDependencies moduleVersion.commonDependencies/}
                            </td>
                            <td>
                                #{moduleDependencies moduleVersion.jvmDependencies/}
                            </td>
                            <td>
                                #{moduleDependencies moduleVersion.jsDependencies/}
                            </td>
                        </tr>
                    </table>
                    #{/if}
                    #{else}
                        #{moduleDependencies moduleVersion.dependencies/}
                    #{/else}
                </td>
            </tr>
        #{/if}
        <tr>
            <th>Usage</th>
            <td>
                <div class="tabbable">
                    <ul class="nav nav-tabs">
                        <li class="active"><a href="#tab1" data-toggle="tab">Import</a></li>
                        #{if moduleVersion.isCarPresent && moduleVersion.isRunnable}
                            <li><a href="#tab2" data-toggle="tab">Run from command-line</a></li>
                            <li><a href="#tab3" data-toggle="tab">Run from Ant</a></li>
                        #{/if}
                        #{if moduleVersion.isScriptsPresent}
                            <li><a href="#tab4" data-toggle="tab">Install scripts from command-line</a></li>
                            <li><a href="#tab5" data-toggle="tab">Install scripts from Ant</a></li>
                        #{/if}
                    </ul>
                    <div class="tab-content">
                        <div class="tab-pane active" id="tab1">
                            <pre> <span class="xml-tag">import</span><span class="xml-attr"> ${module.name} "${moduleVersion.version}"<span class="xml-tag">;</span></span></pre>
                        </div>
                        #{if moduleVersion.isCarPresent && moduleVersion.isRunnable}
                            <div class="tab-pane" id="tab2">
                                <!-- It's hand compiled so it's a pain, but that's a lot more efficient -->
                                #{if moduleVersion.jvmBinMajor >= 3}
                                    <pre>$ <span class="xml-tag">ceylon run</span> <span class="xml-attr">${module.name}/${moduleVersion.version}</span></pre>
                                #{/if}
                                #{else}
                                    <pre>$ <span class="xml-tag">ceylon</span> <span class="xml-attr">${module.name}/${moduleVersion.version}</span></pre>
                                #{/else}
                            </div>
                            <div class="tab-pane" id="tab3">
                                <!-- It's hand compiled so it's a pain, but that's a lot more efficient -->
                            <pre><span class="xml-tag">&lt;property</span> <span class="xml-attr">name</span>=<span class="xml-val">"ceylon.home"</span> <span class="xml-attr">value</span>=<span class="xml-val">"…"</span><span class="xml-tag">/&gt;</span>
<span class="xml-tag">&lt;property</span> <span class="xml-attr">name</span>=<span class="xml-val">"ceylon.ant.lib"</span> 
  <span class="xml-attr">value</span>=<span class="xml-val">"&#36;{ceylon.home}/lib/ceylon-ant.jar"</span><span class="xml-tag">/&gt;</span>
<span class="xml-tag">&lt;path</span> <span class="xml-attr">id</span>=<span class="xml-val">"ant-tasks"</span><span class="xml-tag">&gt;</span>
  <span class="xml-tag">&lt;pathelement</span> <span class="xml-attr">path</span>=<span class="xml-val">"&#36;{ceylon.ant.lib}"</span><span class="xml-tag">/&gt;</span>
<span class="xml-tag">&lt;/path&gt;</span>
<span class="xml-tag">&lt;typedef</span> <span class="xml-attr">resource</span>=<span class="xml-val">"com/redhat/ceylon/ant/antlib.xml"</span> <span class="xml-attr">classpathref</span>=<span class="xml-val">"ant-tasks"</span><span class="xml-tag">/&gt;</span>

<span class="xml-tag">&lt;target</span> <span class="xml-attr">name</span>=<span class="xml-val">"run"</span><span class="xml-tag">&gt;</span>
  <span class="xml-tag">&lt;ceylon-run</span> <span class="xml-attr">module</span>=<span class="xml-val">"${module.name}/${moduleVersion.version}"</span><span class="xml-tag">/&gt;</span>
<span class="xml-tag">&lt;/target&gt;</span></pre>
                            </div>
                        #{/if}
                        #{if moduleVersion.isScriptsPresent}
                            <div class="tab-pane" id="tab4">
                                <!-- It's hand compiled so it's a pain, but that's a lot more efficient -->
                                <pre>$ <span class="xml-tag">ceylon plugin install</span> <span class="xml-attr">${module.name}/${moduleVersion.version}</span></pre>
                            </div>
                            <div class="tab-pane" id="tab5">
                                <!-- It's hand compiled so it's a pain, but that's a lot more efficient -->
                            <pre><span class="xml-tag">&lt;property</span> <span class="xml-attr">name</span>=<span class="xml-val">"ceylon.home"</span> <span class="xml-attr">value</span>=<span class="xml-val">"…"</span><span class="xml-tag">/&gt;</span>
<span class="xml-tag">&lt;property</span> <span class="xml-attr">name</span>=<span class="xml-val">"ceylon.ant.lib"</span> 
  <span class="xml-attr">value</span>=<span class="xml-val">"&#36;{ceylon.home}/lib/ceylon-ant.jar"</span><span class="xml-tag">/&gt;</span>
<span class="xml-tag">&lt;path</span> <span class="xml-attr">id</span>=<span class="xml-val">"ant-tasks"</span><span class="xml-tag">&gt;</span>
  <span class="xml-tag">&lt;pathelement</span> <span class="xml-attr">path</span>=<span class="xml-val">"&#36;{ceylon.ant.lib}"</span><span class="xml-tag">/&gt;</span>
<span class="xml-tag">&lt;/path&gt;</span>
<span class="xml-tag">&lt;typedef</span> <span class="xml-attr">resource</span>=<span class="xml-val">"com/redhat/ceylon/ant/antlib.xml"</span> <span class="xml-attr">classpathref</span>=<span class="xml-val">"ant-tasks"</span><span class="xml-tag">/&gt;</span>

<span class="xml-tag">&lt;target</span> <span class="xml-attr">name</span>=<span class="xml-val">"run"</span><span class="xml-tag">&gt;</span>
  <span class="xml-tag">&lt;ceylon-plugin</span> <span class="xml-attr">mode</span>=<span class="xml-val">install</span> <span class="xml-attr">module</span>=<span class="xml-val">"${module.name}/${moduleVersion.version}"</span><span class="xml-tag">/&gt;</span>
<span class="xml-tag">&lt;/target&gt;</span></pre>
                            </div>
                        #{/if}
                    </div>
                </div>
            </td>
        </tr>
        <tr>
            <th>Module links</th>
            <td>
                <a href="@{Repo.members(module.name,moduleVersion.version)}" title="View module members"><i class="icon-eye-open"></i> Members</a><br/>
                <a href="@{Repo.importers(module.name,moduleVersion.version)}" title="View modules importing this module"><i class="icon-eye-open"></i> Imported By</a><br/>
                #{if module.homeURL}
                    <a href="${module.homeURL}" title="Module web site"><i class="icon-home"></i> Home</a><br/>
                #{/if}
                #{if module.codeURL}
                    <a href="${module.codeURL}" title="Module code repository"><i class="icon-heart"></i> Code repository</a><br/>
                #{/if}
                #{if module.issueTrackerURL}
                    <a href="${module.issueTrackerURL}" title="Module issue tracker" id="issues"><i class="icon-exclamation-sign"></i> Issue tracker</a><br/>
                #{/if}
                <a href="${util.Util.viewRepoUrl(moduleVersion.path)}" title="Browse module files"><i class="icon-folder-open"></i> Browse</a><br/>
                #{if moduleVersion.isJarPresent}
                    <a href="${util.Util.viewRepoUrl(moduleVersion.jarPath)}" title="Download legacy Jar archive"><i class="icon-download"></i> Download .jar</a><br/>
                #{/if}
                #{if moduleVersion.isCarPresent}
                    <a href="${util.Util.viewRepoUrl(moduleVersion.carPath)}" title="Download module JVM archive"><i class="icon-download"></i> Download .car</a><br/>
                #{/if}
                #{else}
                    <i class="icon-remove"></i> No .car archive<br/>
                #{/else}
                #{if moduleVersion.isJsPresent}
                    <a href="${util.Util.viewRepoUrl(moduleVersion.jsPath)}" title="Download module JavaScript archive"><i class="icon-download"></i> Download .js</a><br/>
                #{/if}
                #{else}
                    <i class="icon-remove"></i> No .js archive<br/>
                #{/else}
                #{if moduleVersion.isSourcePresent}
                    <a href="${util.Util.viewRepoUrl(moduleVersion.sourcePath)}" title="Download module source archive"><i class="icon-heart"></i> Download source archive</a><br/>
                #{/if}
                #{else}
                    <i class="icon-remove"></i> No source archive<br/>
                #{/else}
                #{if moduleVersion.isScriptsPresent}
                    <a href="${util.Util.viewRepoUrl(moduleVersion.scriptsPath)}" title="Download module scripts archive"><i class="icon-download"></i> Download scripts archive</a><br/>
                    #{if moduleVersion.scripts.size() > 0}
                        <a href="@{Repo.scripts(module.name,moduleVersion.version)}" title="View module scripts"><i class="icon-eye-open"></i> Scripts</a><br/>
                    #{/if}
                #{/if}
                #{if moduleVersion.isDocPresent}
                    <a href="${util.Util.viewRepoUrl(moduleVersion.docPath)}" title="Download module documentation"><i class="icon-book"></i> Download module documentation</a><br/>
                #{/if}
                #{else}
                    <i class="icon-remove"></i> No module documentation<br/>
                #{/else}
                #{if moduleVersion.isAPIPresent}
                    <a href="@{Repo.viewDoc(module.name, moduleVersion.version)}" title="Browse module API documentation"><i class="icon-book"></i> View API documentation</a><br/>
                #{/if}
                #{else}
                    <i class="icon-remove"></i> No API documentation<br/>
                #{/else}
            </td>
        </tr>
    </tbody>
</table>
